package com.netted.operationassistant.reveiver;

import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.sdk.android.push.MessageReceiver;
import com.alibaba.sdk.android.push.notification.CPushMessage;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;

import java.util.Map;
import java.util.Set;

/**
 * Created by lu on 2018/7/6.
 */

public class MyMessageReceiver extends MessageReceiver {


    @Override
    public void onReceive(Context context, Intent intent) {
        super.onReceive(context,intent);
        String action = intent.getAction();


        Set<String> ks = intent.getExtras().keySet();
        String body = intent.getExtras().getString("body");
        LogUtils.e("action#######################:"+action+"   #######body####### "+body);
        if (body == null){return;}
        JSONObject bodyJson = JSONObject.parseObject(body);
        ToastUtils.showLong("title:"+bodyJson.getString("title")+",content:"+bodyJson.getString("content")
                +",type:"+bodyJson.getString("type"));
        LogUtils.e("getDataString#######################:"+intent.getDataString());


    }


    @Override
    public void onMessage(Context context, CPushMessage cPushMessage) {

        LogUtils.e( "onMessage, ##################: " + JSONObject.toJSONString(cPushMessage));
    }

    @Override
    public void onNotification(Context context, String title, String summary, Map<String, String> extraMap) {
        // TODO 处理推送通知
        ToastUtils.showLong("onNotification, title: " + title+"     onNotification, context: " + context);
        LogUtils.e( "Receive notification, title: " + title + ", summary: " + summary + ", extraMap: " + extraMap);
    }

    @Override
    public void onNotificationOpened(Context context, String title, String summary, String extraMap) {
        ToastUtils.showLong("onNotificationOpened, messageId: " + title);
        LogUtils.e( "onNotificationOpened, title: " + title + ", summary: " + summary + ", extraMap:" + extraMap);
    }
    @Override
    protected void onNotificationClickedWithNoAction(Context context, String title, String summary, String extraMap) {
        LogUtils.e("onNotificationClickedWithNoAction, title: " + title + ", summary: " + summary + ", extraMap:" + extraMap);
    }
    @Override
    protected void onNotificationReceivedInApp(Context context, String title, String summary, Map<String, String> extraMap, int openType, String openActivity, String openUrl) {
        LogUtils.e( "onNotificationReceivedInApp, title: " + title + ", summary: " + summary + ", extraMap:" + extraMap + ", openType:" + openType + ", openActivity:" + openActivity + ", openUrl:" + openUrl);
    }
    @Override
    protected void onNotificationRemoved(Context context, String messageId) {
        LogUtils.e( "onNotificationRemoved");
    }
}
